#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const inquirer = require('inquirer')
const ejs = require('ejs')

inquirer.prompt([
    {
      type: 'input',
      name: 'name',
      message: 'Project name?'
    }, {
      type: 'input',
      name: 'version',
      message: 'Project version?'
    }
  ]).then(result => {
    const tmplDir = path.join(__dirname, 'templates');
    const destDir = process.cwd();
    fs.readdir(tmplDir, (err, filesPath) => {
        if(err) throw err
        filesPath.forEach(file => {
          console.log(file)
            ejs.renderFile(path.join(tmplDir, file), result, (err, renderFile) => {
                if(err) throw err
                console.log(renderFile)
                fs.writeFileSync(path.join(destDir, file), renderFile)
            })
        })
    })
})
